package cn.com.dragonpass.infra.settle.service.impl;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ExecutorConfig {
    private final static int MAX_POOL_SIZE = Runtime.getRuntime().availableProcessors();
    private final static int QUEUE_SIZE = 500;
    private volatile static ExecutorService executorService;

    public static ExecutorService getThreadPool() {
        if (executorService == null) {
            synchronized (ExecutorConfig.class) {
                if (executorService == null) {
                    executorService = newThreadPool();
                }
            }
        }
        return executorService;
    }

    private static ExecutorService newThreadPool() {
        int corePool = Math.min(4, MAX_POOL_SIZE);
        return new ThreadPoolExecutor(corePool, MAX_POOL_SIZE, 10000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(QUEUE_SIZE), new ThreadPoolExecutor.AbortPolicy());
    }

    private ExecutorConfig() {
    }

}


------------------------------------


 void adjustDetailField(List<Map<String, Object>> maps, boolean isCalculate,List<CreateSettleSumDto.Create> reportSumVolist) {
        Map<String, SalesAgreement> aggs = new HashMap<>();
        String sumCode = null;
        String productType=null;
        //批量更新
        List<List<Map<String, Object>>> partitionMaps = Lists.partition(maps, 20);
        long begintime = System.currentTimeMillis();
        List<Runnable> runnableslist=new ArrayList<>();
        for (List<Map<String, Object>> partitionMap : partitionMaps) {
            List<SettleCusDetail>  settleCusDetailList=new ArrayList<>();

           runnableslist.add(()->{
               System.out.println(Thread.currentThread().getName()+"--->现场处理。。。。。"+partitionMap.size()+"");
           });
        }
         boolean execute = multiThreadTransactionManager.execute(runnableslist);
        System.out.println(execute);

